#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#define MAX_N 2000

using namespace std;

int a[MAX_N],b[MAX_N],c[MAX_N],d[MAX_N];
int n;

struct lnode{
    int val;
    int cnt,self;
    int lch,rch;
}tree[MAX_N];
int tree_cnt;

int mktree(int l,int r){
    if (r<l) return -1;
    int m = (l+r) >> 1;
    int lch = mktree(l,m-1);
    int rch = mktree(m+1,r);
    tree_cnt++;
    tree[tree_cnt].lch = lch;
    tree[tree_cnt].rch = rch;
    tree[tree_cnt].val = m;
    return tree_cnt;
}

void Insert(int p,int root, int &ls){
   // cout << p<<" "<<tree[root].val<<" " << ls <<endl;
    if (p==tree[root].val){
        ls += tree[root].cnt;
        tree[root].self++;
        return ;
    }

    if (p<tree[root].val){
        ls += tree[root].cnt + tree[root].self;
        Insert(p,tree[root].lch,ls);
        return ;
    }

    if (p>tree[root].val){
        tree[root].cnt++;
        Insert(p,tree[root].rch,ls);
        return ;
    }


}

int main(){

   // freopen("2188.txt","r",stdin);
    scanf("%d",&n);
    for (int i = 1 ; i<=n ; i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        c[a[i]]=i;
    }
    for (int i = 1; i<=n;i++){
        d[c[b[i]]] = i;
    }

//for (int i =1 ; i<=n ; i++) cout <<d[i]<<endl;

    int ans = 0 , ls=0;
    memset(tree,0,sizeof(tree));
    int root = mktree(1,n);
    for (int i = 1; i<=n;i++){
        ls = 0;
        Insert(d[i],root,ls);
        ans += ls;
    }


    cout << ans <<endl;



    return 0;
}
